home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-19 | 3.8 KB | 130 lines | [TEXT/R*ch] |
- Splitting Windows in MacApp
-
- © Copyright 1995 by Tom Otvos and MacTech Magazine
-
- ————————————————————————————————————————————————————————————————————
-
- class TSplitterControl : public TControl
- {
- private:
- TView* fFirstView;
- TView* fSecondView;
- public:
- virtual pascal void Initialize();
- virtual pascal void DoMouseCommand(
- VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);
- virtual pascal void Draw(const VRect& area);
- // override
- virtual pascal void SuperViewChangedFrame(
- const VRect& oldFrame,
- const VRect& newFrame,
- Boolean invalidate);
- virtual pascal void SetSplitViews(
- TView* firstView,
- TView* secondView);
- };
-
- ————————————————————————————————————————————————————————————————————
-
- pascal void TSplitterControl::DoMouseCommand(
- VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis)
- // override
- {
- // mouse hits in our control will immediately post a splitter
- // tracker command
- TSplitterTracker* splitter = new TSplitterTracker;
- splitter->ISplitterTracker(fFirstView, fSecondView, this, theMouse);
- this->PostCommand(splitter);
-
- inherited::DoMouseCommand(theMouse, event, hysteresis);
- }
-
-
- ————————————————————————————————————————————————————————————————————
-
- class TSplitterTracker : public TTracker
- {
- private:
- VCoordinate fDelta;
- TView* fFirstView;
- TView* fSecondView;
- TView* fSplitter;
- public:
- virtual pascal void ISplitterTracker(
- TView* firstView,
- TView* secondView,
- TView* splitter,
- VPoint& itsMouse);
- virtual pascal void TrackConstrain(
- TrackPhase aTrackPhase,
- const VPoint& anchorPoint,
- const VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean mouseDidMove);
- // override
- virtual pascal void TrackFeedback(
- TrackPhase aTrackPhase,
- const VPoint& anchorPoint,
- const VPoint& previousPoint,
- const VPoint& nextPoint,
- Boolean mouseDidMove,
- Boolean turnItOn);
- // override
- virtual pascal void DoIt(); // override
- };
-
- ————————————————————————————————————————————————————————————————————
-
- inherited::TrackConstrain(aTrackPhase, anchorPoint,
- previousPoint, nextPoint,
- mouseDidMove);
- if (mouseDidMove)
- // limit tracking to one direction only
- nextPoint.h = previousPoint.h;
-
- ————————————————————————————————————————————————————————————————————
-
- switch (aTrackPhase) {
- case trackBegin: // initialize our track delta
- fDelta = 0;
- break;
- case trackEnd: // how far did we go?
- // anchor point is always in splitter coordinates
- anchor = anchorPoint;
- fSplitter->LocalToWindow(anchor);
- next = nextPoint;
- // next point is always in view coordinates
- fView->LocalToWindow(next);
- fDelta = next.v - anchor.v;
- break;
- }
- // draw some nice feedback for the user
- PenSize(2, 2);
- PenPat(&qd.gray);
- fView->GetQDExtent(qdExtent);
- MoveTo(qdExtent[topLeft].h, nextPoint.v);
- LineTo(qdExtent[botRight].h, nextPoint.v);
-
- ————————————————————————————————————————————————————————————————————
- pascal void TSplitterTracker::DoIt()
- {
- VRect frame1, frame2;
- // adjust fDelta so neither view becomes invalid
- fFirstView->GetFrame(frame1);
- if (fDelta < frame1.top - frame1.bottom)
- fDelta = frame1.top - frame1.bottom;
- fSecondView->GetFrame(frame2);
- if (fDelta > frame2.bottom - frame2.top)
- fDelta = frame2.bottom - frame2.top;
- // adjust the first view from the bottom, the second from the top
- frame1.bottom += fDelta;
- fFirstView->SetFrame(frame1, kRedraw);
- frame2.top += fDelta;
- fSecondView->SetFrame(frame2, kRedraw);
- }
-
-